$(document).ready(function(){
    $('#form_translate')
        .bootstrapValidator({
        message: 'This value is not valid',
        excluded: [':disabled'],
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            'data[Translate][key_word]': {
                selector:"#TranslateKeyWord",
                validators: {
                    notEmpty: {
                        message: 'Từ khóa không được để trống'
                    },
                }
            }
        }
    })
    // Called when a field is invalid
    .on('error.field.bv', function(e, data) {
        // data.element --> The field element

        var $tabPane = data.element.parents('.tabbable'),
            tabId    = $tabPane.attr('id');

        $('a[href="#' + tabId + '"][data-toggle="tab"]')
            .parent()
            .find('i')
            .removeClass('fa-check')
            .addClass('fa-times');
    })
    // Called when a field is valid
    .on('success.field.bv', function(e, data) {
        // data.bv      --> The BootstrapValidator instance
        // data.element --> The field element

        var $tabPane = data.element.parents('.tabbable'),
            tabId    = $tabPane.attr('id'),
            $icon    = $('a[href="#' + tabId + '"][data-toggle="tab"]')
                        .parent()
                        .find('i')
                        .removeClass('fa-check fa-times');

        // Check if the submit button is clicked
        if (data.bv.getSubmitButton()) {
            // Check if all fields in tab are valid
            var isValidTab = data.bv.isValidContainer($tabPane);
            $icon.addClass(isValidTab ? 'fa-check' : 'fa-times');
        }
    });
    
    $('.delete_translate').click(function(){
        var translate_id = $(this).attr('translate_id');
        var array_attr = {confirm_delete_translate:"confirm_delete_translate", translate_id:translate_id}; 
        open_modal_confirm('Xác nhận', 'Bạn có chắc chắn muốn xóa...', array_attr);
    });

    $('button[confirm_delete_translate=confirm_delete_translate]').live('click',function(){
        var translate_id = $(this).attr('translate_id');
        $.ajax({
                url:admin_url + 'ajax/delete_translate',
                type:'post',
                data:{translate_id:translate_id},
                success:function(data){
                    location.reload(); 
                }
            });
    });


    
});